
class Pages < Controller
  def index e
    s = '<h1>Stránky</h1>'
    s << '<p><a href="'+link(:add)+'">přidej</a></p>'
    Page.all.each { |page|
      s << "<p><a href=\"#{link('edit/'+page.id.to_s)}\">#{page.title}</a></p>"
    }
    s
  end

  def add e
    s = '<h1>Přidat stránku</h1>'

    form = Page::AdminForm.new()
    form.env = e.env

    if e.request.post?
      form.handle e.params
    end

    s << form.to_s
    s
  end

  def edit e
    s = '<h1>Upravit stránku</h1>'

    page = Page.get(e.env[:unprocessed_tail].first.to_i)

    form = Page::AdminForm.new()
    form.fill page.attributes

    if e.request.post?
      form.handle e.params
    end

    s << form.to_s
    s
  end
end